package cn.tedu.sort;

import org.junit.Test;

public class BasicSort {
    protected Integer numbers[];

    protected void generateNumbers() {
        int count = (int) (Math.random() * 100);
        numbers = new Integer[count];
        System.out.println("Total count: " + numbers.length);
        System.out.println("Numbers:");
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (int) (Math.random() * 100);
        }
        outputNumbers();
    }

    private void outputNumbers() {
        String str = "";
        for (int i = 0; i < numbers.length; i++) {
            str += numbers[i] + " ";
        }
        System.out.println(str);
    }

    protected void show() {
        boolean sorted = isSorted(numbers);
        System.out.println("Number sorted: " + sorted);
        System.out.println("Sorted numbers:");
        outputNumbers();
    }

    protected boolean less(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    protected void exch(Comparable[] arr, int i, int j) {
        Comparable t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }

    protected boolean isSorted(Comparable[] arr) {
        for (int i = 1; i < arr.length; i++) {
            if (less(arr[i], arr[i - 1]))
                return false;
        }
        return true;
    }

    protected void sort(Comparable[] arr) {}
}
